<template>
  <div style="height:100%;width:100%;position:relative;">
      <div class="pagetop">
          <div style="width:100%">
              <div style="width:100%;float:left">
                  <table style="font-size:12px" class="table1style">
                      <tr>
                          <td style="text-align:right">交班日期</td>
                          <td>
                              <el-date-picker type="date" value-format="yyyy-MM-dd" :clearable="false" style="width: 130px"  v-model="searchObj.startdt" key="1"></el-date-picker>
                          </td>
                          <td>至</td>
                          <td>
                              <el-date-picker type="date" value-format="yyyy-MM-dd" :clearable="false" style="width: 130px"  v-model="searchObj.enddt" key="2"></el-date-picker>
                          </td>
                          <td style="text-align:right">工作组</td>
                          <td>
                              <rm-ddl-common datatype="labgroup" kindno="1" dataname="工作组" width="130px" v-model="searchObj.labgroupid" ></rm-ddl-common>
                          </td>
                          <td style="text-align:right">交班人</td>
                          <td>
                              <rm-ddl-common datatype="userinfo" kindno="1" dataname="交班人" v-model="searchObj.checkoutuser" width="100%" ></rm-ddl-common>
                          </td>
                          <td style="text-align:right">接班人</td>
                          <td>
                              <rm-ddl-common datatype="userinfo" kindno="1" dataname="接班人" v-model="searchObj.checkinuser" width="100%" ></rm-ddl-common>
                          </td>
                      </tr>
                  </table>
              </div>
              <div style="width:100%;float:left;">
                  <table style="float:right">
                      <tr>
                          <td>
                              <el-button icon="el-icon-search" type="primary"  @click="QueryHandOver" :disabled="changeflag" v-has="'PINQUERY'" >查询</el-button>
                          </td>
                          <td>
                              <el-button icon="el-icon-plus" @click="AddHandOver" :disabled="changeflag" v-has="'PADD'" >新增</el-button>
                          </td>
                          <td>
                              <el-button icon="el-icon-delete" @click="DeleteHandOver" :disabled="changeflag" v-has="'PDELETE'" >删除</el-button>
                          </td>
                          <td>
                              <el-button icon="el-icon-document" @click="SaveHandOver" :disabled="!changeflag" v-has="'PMODIFY'" >保存</el-button>
                          </td>
                          <td>
                              <el-button icon="el-icon-close" :disabled="!changeflag" @click="CancelChange" >取消</el-button>
                          </td>
                          <td>
                              <el-button icon="el-icon-s-check" :disabled="changeflag" @click="ConfirmHand" v-has="'PMODIFY'" >确认接班</el-button>
                          </td>
                          <td>
                              <el-button icon="el-icon-printer" :disabled="changeflag" v-has="'PPRINT'" @click="printrecord">打印</el-button>
                          </td>
                          <td>
                              <el-button icon="el-icon-setting" :disabled="changeflag" v-has="'PPRINT'" @click="RptStyleSetting">调整</el-button>
                          </td>
                          <td>
                              <el-button icon="el-icon-files" :disabled="changeflag" v-has="'PEXPORT'" @click="ExportMasterExcel">导出</el-button>
                          </td>
                      </tr>
                  </table>
              </div>
          </div>
      </div>
      <div class="pagecenter">
          <rm-layout-right splitcolor="white" :splitwidth=5 :fixsize=650 :minfixsize=650 >
              <vxe-table :data.sync="handoverTableData" :loading="loading" :select-config="{reserve: true}" :edit-config="{showIcon:false}" :sort-config="{trigger: 'cell'}" border height="auto" highlight-current-row highlight-hover-column :highlight-hover-row="false" how-header-overflow ref="xTable" resizable show-overflow size="mini" stripe @current-change="currentChangeEvent" :row-class-name="xTableRowClassName" :disabled="!changeflag">
                  <vxe-table-column field="hotime" title="交班时间" width="120" header-align="center" sortable></vxe-table-column>
                  <vxe-table-column field="honame" title="交班名称" width="150" header-align="center" sortable></vxe-table-column>
                  <vxe-table-column field="checkoutuser" title="交班人" width="87" header-align="center" align="center" :formatter="formatFun" sortable></vxe-table-column>
                  <vxe-table-column field="checkinuser" title="接班人" width="87" header-align="center" align="center" :formatter="formatFun" sortable></vxe-table-column>
                  <vxe-table-column field="checkintime" title="接班时间" width="120" header-align="center" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="comments" title="交班备注" width="150" header-align="center" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="labgroupid" title="工作组" width="87" header-align="center" align="center" :formatter="formatFun" sortable></vxe-table-column>
                  <vxe-table-column field="hoid" title="交班ID" width="87" header-align="center" align="center" sortable></vxe-table-column>
              </vxe-table>
          
              <template v-slot:fix>
                  <rm-layout-top splitcolor="white" :splitwidth=5 :fixsize=205 :minfixsize=205 :maxfixsize=205>
                      <template v-slot:fix>
                          <div style="height:100%;border:1px solid #CCC">
                              <el-form ref="form" :model="handover" label-width="80px">
                                  <table class="table1style" style="font-size:12px;width:100%">
                                      <tr>
                                          <td align="right">
                                              <font color="#F56C6C">交班ID</font>
                                          </td>
                                          <td>
                                              <el-input v-model="handover.hoid" :readonly="true" :disabled="true" ref="hoid" ></el-input>
                                          </td>
                                          <td align="right">工作组</td>
                                          <td>
                                              <rm-ddl-common datatype="labgroup" dataname="工作组" v-model="handover.labgroupid" width="100%" @change="labgroup_Change"  :readonly="handover.checkinuser != ''" :disabled="!iseditflag || handover.checkinuser!= ''"></rm-ddl-common>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td align="right">
                                              <font>交班名称</font>
                                          </td>
                                          <td colspan="3">
                                              <el-input v-model="handover.honame" ref="honame" @change="HasChange"  @input="HasChange" :readonly="handover.checkinuser != ''" :disabled="!iseditflag || handover.checkinuser!= ''" ></el-input>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td align="right">
                                              <font>交班时间</font>
                                          </td>
                                          <td>
                                              <el-date-picker type="datetime" value-format="yyyy-MM-dd HH:mm:ss" :clearable="true" style="width: 100%"  v-model="handover.hotime" :readonly="handover.checkinuser != ''"  @change="HasChange"  :disabled="!iseditflag || handover.checkinuser!= ''"></el-date-picker>
                                          </td>
                                          <td align="right">交班人</td>
                                          <td>
                                              <rm-ddl-common datatype="userinfo" kindno="1" dataname="" :ishidelabel="true" v-model="handover.checkoutuser" width="100%" :readonly="true" :disabled="true" :onlyshow="true"></rm-ddl-common>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td align="right">
                                              <font>接班时间</font>
                                          </td>
                                          <td><el-date-picker type="datetime" value-format="yyyy-MM-dd HH:mm:ss" :clearable="true" style="width: 100%"  v-model="handover.checkintime" :readonly="true" :disabled="true" ></el-date-picker>
                                          </td>
                                          <td align="right">接班人</td>
                                          <td>
                                              <rm-ddl-common datatype="userinfo" kindno="1" dataname="" :ishidelabel="true" v-model="handover.checkinuser" width="100%" :readonly="true" :disabled="true" :onlyshow="true"></rm-ddl-common>
                                          </td>
                                          
                                      </tr>
                                      <tr>
                                          <td align="right">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注</td>
                                          <td colspan="3">
                                                <el-input  type="textarea" rows="4" ref="comments"   @input.native="HasChange" @dblclick.native="DbTextArea" @change="HasChange"   v-model="handover.comments"  width="100%"  :disabled="!iseditflag || handover.checkinuser!= ''" :key="comments_key" :readonly="handover.checkinuser!= ''">
                                              </el-input>
                                          </td>
                                      </tr>
                                  </table>
                              </el-form>
                          </div>
                      </template>
                      <div class="right-bottom" style="height:100%;width:100%;background-color:#FFFFFF;position: absolute;">
                          <div class="right-bottom-top" style="height:65px;width:100%;float:left">
                              <div>
                                  <table class="table1style" style="font-size:12px;width:100%">
                                      <tr>
                                              <td align="right">
                                                  <font>统计时间</font>
                                              </td>
                                              <td>
                                                  <el-date-picker type="datetime" value-format="yyyy-MM-dd HH:mm:ss" :clearable="false" style="width: 100%"  v-model="handover.class_starttime" key="1"  :disabled="!iseditflag || handover.checkinuser != ''" :readonly="handover.checkinuser != ''" @change="HasChange"></el-date-picker>
                                              </td>
                                              <td align="center">至</td>
                                              <td>
                                                  <el-date-picker type="datetime" value-format="yyyy-MM-dd HH:mm:ss" :clearable="false" style="width: 100%"  v-model="handover.class_endtime" key="2"  :disabled="!iseditflag || handover.checkinuser != ''" :readonly="handover.checkinuser != ''" @change="HasChange"></el-date-picker>
                                              </td>
                                              <td align="right">
                                                  <font>班次</font>
                                              </td>
                                              <td>
                                                  <el-select placeholder="请选择" style="width: 80px" v-model="handover.classid" @change="classChange"  :readonly="handover.checkinuser != ''" :disabled="!iseditflag || handover.checkinuser != ''">
                                                      <el-option v-for="(item,index) in offclassOption" :label="item.classname" :value="item.classid" :key="index" @click.native="classChange"></el-option>
                                                  </el-select>
                                              </td>
                                          </tr>
                                  </table>
                              </div>
                          </div>
                          <div class="right-bottom-bottom" style="width:100%;">
                              <vxe-table :data="handoverDetTableData" :loading="loading1" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="auto" :edit-config="{trigger: 'click', mode: 'cell', showStatus: true,showIcon:false}"  :keyboard-config="keyConfig" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="xTable1" resizable show-overflow size="mini" stripe >
                                  <vxe-table-column field="hodetid" title="明细ID" width="40" header-align="center"></vxe-table-column>
                                  <vxe-table-column field="rptunitid" title="报告单元" width="100" header-align="center" :edit-render="{ name: 'select', autoselect: true}">
                                      <template v-slot:edit="{ row }">
                                          <el-select v-model="row.rptunitid"  filterable clearable :disabled="!iseditflag || handover.checkinuser != ''" @change="HasChange"  style="width:100%">
                                              <el-option v-for="(item,index) in rptunitOption" :key="index" :value="item.data" :label="item.display"></el-option>
                                          </el-select>
                                      </template>
                                      <template v-slot="{ row }">
                                          <span>{{getUnitShowName(row.rptunitid)}}</span>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="rechkeds" title="已审核报告数" width="50" header-align="center" :edit-render="{ name: 'input', autoselect: true}">
                                      <template v-slot:edit="{ row }">
                                          <el-input type="number" v-model="row.rechkeds" :disabled="!iseditflag || handover.checkinuser != ''" @change="HasChange" @input="HasChange"   oninput="if(value < 1){ value = undefined}"></el-input>
                                      </template>
                                      <template v-slot="{ row }">
                                          <span>{{row.rechkeds}}</span>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="norechks" title="未审核报告数" width="50" header-align="center" :edit-render="{ name: 'input', autoselect: true}">
                                      <template v-slot:edit="{ row }">
                                          <el-input type="number" v-model="row.norechks" :disabled="!iseditflag || handover.checkinuser != ''" @change="HasChange" @input="HasChange"   oninput="if(value < 1){ value = undefined}"></el-input>
                                      </template>
                                      <template v-slot="{ row }">
                                          <span>{{row.norechks}}</span>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="allalerts" title="危急值总数" width="50" header-align="center" :edit-render="{ name: 'input', autoselect: true}">
                                      <template v-slot:edit="{ row }">
                                          <el-input type="number" v-model="row.allalerts" :disabled="!iseditflag || handover.checkinuser != ''"   @change="HasChange" @input="HasChange" oninput="if(value < 1){ value = undefined}"></el-input>
                                      </template>
                                      <template v-slot="{ row }">
                                          <span>{{row.allalerts}}</span>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="alerts" title="危急值上报数" width="50" header-align="center" :edit-render="{ name: 'input', autoselect: true}">
                                      <template v-slot:edit="{ row }">
                                          <el-input type="number" v-model="row.alerts" :disabled="!iseditflag || handover.checkinuser != ''"   @change="HasChange" @input="HasChange" oninput="if(value < 1){ value = undefined}"></el-input>
                                      </template>
                                      <template v-slot="{ row }">
                                          <span>{{row.alerts}}</span>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="redos" title="项目复查数" width="50" header-align="center" :edit-render="{ name: 'input', autoselect: true}">
                                      <template v-slot:edit="{ row }">
                                          <el-input type="number" v-model="row.redos" :disabled="!iseditflag || handover.checkinuser != ''"  @change="HasChange" @input="HasChange"  oninput="if(value < 1){ value = undefined}"></el-input>
                                      </template>
                                      <template v-slot="{ row }">
                                          <span>{{row.redos}}</span>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="rechks" title="解除审核报告数" width="50" header-align="center" :edit-render="{ name: 'input', autoselect: true}">
                                      <template v-slot:edit="{ row }">
                                          <el-input type="number" v-model="row.rechks" :disabled="!iseditflag || handover.checkinuser != ''"  @change="HasChange" @input="HasChange"  oninput="if(value < 1){ value = undefined}"></el-input>
                                      </template>
                                      <template v-slot="{ row }">
                                          <span>{{row.rechks}}</span>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="overpres" title="超时未报告数" width="50" header-align="center" :edit-render="{ name: 'input', autoselect: true}">
                                      <template v-slot:edit="{ row }">
                                          <el-input type="number" v-model="row.overpres" :disabled="!iseditflag || handover.checkinuser != ''"   @change="HasChange" @input="HasChange" oninput="if(value < 1){ value = undefined}"></el-input>
                                      </template>
                                      <template v-slot="{ row }">
                                          <span>{{row.overpres}}</span>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="nocharges" title="计价失败数" width="50" header-align="center" :edit-render="{ name: 'input', autoselect: true}">
                                      <template v-slot:edit="{ row }">
                                          <el-input type="number" v-model="row.nocharges" :disabled="!iseditflag || handover.checkinuser != ''"   @change="HasChange" @input="HasChange" oninput="if(value < 1){ value = undefined}"></el-input>
                                      </template>
                                      <template v-slot="{ row }">
                                          <span>{{row.nocharges}}</span>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="emernorechks" title="加急报告未审核数" width="50" header-align="center" :edit-render="{ name: 'input', autoselect: true}">
                                      <template v-slot:edit="{ row }">
                                          <el-input type="number" v-model="row.emernorechks" :disabled="!iseditflag || handover.checkinuser != ''"  @change="HasChange" @input="HasChange"  oninput="if(value < 1){ value = undefined}"></el-input>
                                      </template>
                                      <template v-slot="{ row }">
                                          <span>{{row.emernorechks}}</span>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="alertsnorechks" title="危急值报告未审核数" width="50" header-align="center" :edit-render="{ name: 'input', autoselect: true}">
                                      <template v-slot:edit="{ row }">
                                          <el-input type="number" v-model="row.alertsnorechks" :disabled="!iseditflag || handover.checkinuser != ''"   @change="HasChange" @input="HasChange" oninput="if(value < 1){ value = undefined}"></el-input>
                                      </template>
                                      <template v-slot="{ row }">
                                          <span>{{row.alertsnorechks}}</span>
                                      </template>
                                  </vxe-table-column>
                                  <template v-slot:fix>
                                                  <div style="font-size:12px;padding-top:3px;background-color:#fff;text-align:center;position: relative;">
                                                      <el-button icon="el-icon-plus" @click="btnAddHandOverDet" :disabled="!iseditflag || handover.checkinuser != ''" v-has="'PMODIFY'" >新增</el-button>
                                                      <el-button icon="el-icon-delete" @click="btnDeleteHandOverDet" :disabled="!iseditflag || handover.checkinuser != ''" v-has="'PMODIFY'">删除</el-button>
                                                      <el-button icon="el-icon-files" v-has="'PEXPORT'" @click="ExportDeatilExcel">导出</el-button>
                                                      <el-button icon="el-icon-setting" :disabled="!iseditflag" v-has="'PSETUP'" @click="setupDialogVisible=true">设置</el-button>
                                                      <el-button icon="el-icon-s-data" @click="btnStatisticsData" :disabled="!iseditflag || handover.checkinuser != ''" v-has="'PCALC'">重新计算</el-button>
                                                  </div>
                                  </template>
                              </vxe-table>
                          </div>
                          
                      </div>
                  </rm-layout-top>
              </template>
          </rm-layout-right>
      </div>
      <el-dialog title="计算设置" width="500px" :visible.sync="setupDialogVisible">
          <table>
              <tr>
                  <td style="text-align:left;font-size:12px;width:10px">
                      1.
                  </td>
                  <td style="text-align:left;font-size:12px;">
                      <el-checkbox label="不显示无数据的行" v-model="set_shownodata" @change="shownodataChange"></el-checkbox>
                  </td>
                  <td></td>
                  <td></td>
              </tr>
              <tr>
                  <td style="text-align:left;font-size:12px;width:10px">
                      2.
                  </td>
                  <td style="text-align:left;font-size:12px;">解除审核报告数,剔除首次审核时间距最后审核时间不超过</td>
                  <td style="text-align:left;font-size:12px;">
                      <el-input v-model="set_unchecktime" style="float:left;width: 50px;" @change="unchecktimeChange"></el-input>
                  </td>
                  <td style="text-align:left;font-size:12px;">
                      分钟的数据
                  </td>
              </tr>
              <tr style="text-align:right">
                  <td style="padding-top: 5px;" colspan="4">
                      <el-button style="margin: 0px 0px 0px 0px" @click="setupDialogVisible=false" v-has="'PINQUERY'">确定</el-button>&nbsp;
                      <el-button style="margin: 0px 0px 0px 0px" @click="setupDialogVisible=false" v-has="'PINQUERY'">取消</el-button>
                  </td>
              </tr>
          </table>
      </el-dialog>
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="检验科交接班备注" :visible.sync="dialogTablePopVisible">
          <rm-pop-common ref="popcom" @change="popcomchange" @cancel="dialogTablePopVisible=false;" :multiple="false" kindno="LABHANDOVERNOTE" datatype="seccode"></rm-pop-common>
      </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  name: "LIS360",
  data() {
      return {
          searchObj: {
              startdt: this.$pub.InitDateTime2(7).datefrom,
              enddt: this.$pub.InitDateTime2(7).dateto,
              labgroupid: "",
              checkoutuser:"",
              checkinuser:"",
          },
          loading: false,
          loading1: false,
          disabled: true,
          handoverTableData: [],
          handoverDetTableData: [],
          loginemployee:{},
          handover: {
              hoid: "",
              hotime: "",
              honame: "",
              checkoutuser: "",
              checkinuser: "",
              checkintime: "",
              comments: "",
              labgroupid: "",
              classid: "",
              class_starttime: XEUtils.toDateString(new Date(), "yyyy-MM-dd") + " 00:00:00",
              class_endtime: XEUtils.toDateString(new Date(), "yyyy-MM-dd") + " 23:59:59",
          },
          keyConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
              isArrow: true,
          },
          offclassOption:[],//班次
          selrow: {}, //选中行
          labgroupOption: [], //工作组 
          userOption:[],
          rptunitOption:[],
          changeflag:false,
          iseditflag:false,
          setupDialogVisible:false,
          set_shownodata:false,
          set_unchecktime:"",
          dialogTablePopVisible:false,
          comments_key: 0,
      };
  },
  created() {
      this.initPage();
      this.initOption();
      
  },
  computed: {
  },
  watch: {
  },
  mounted() {
      
  },
  updated() {},
  methods: {

      initPage(){
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS360",
                  method: "post",
                  data: {
                      action: "initPage",
                  },
              }).then((res) => {
                  
                  this.loginemployee = res.employee;
                  this.searchObj.labgroupid = res.employee.labgroupid;
              })
          this.set_shownodata = localStorage.getItem("lis360set_shownodata") == "1" ? true:false;
          this.set_unchecktime = localStorage.getItem("lis360set_unchecktime");
      },

      //初始化 获取Options 用于格式化表格
      async initOption(){
          try{
              const res = await this.$tool
              .request({
                  url: "LIS/LIS3/LIS360",
                  method: "post",
                  data: {
                      action: "initOption",
                  },
              })
              this.offclassOption = res.offclassOption;
              if(this.offclassOption && this.offclassOption.length > 0){
                  if(!this.handover.classid) this.handover.classid = this.offclassOption[0].classid;
              }
              this.labgroupOption = res.labgroupOption;
              this.userOption = res.userOption;
              this.rptunitOption = res.rptunitOption;
              this.QueryHandOver();
          }catch(e){
              this.$message.warning(e);
          }
      },

      classChange(){
          this.HasChange();
          this.handover.class_starttime = this.getClassStartTime(this.handover.classid);
          this.handover.class_endtime = this.getClassEndTime(this.handover.classid);
          this.handover.honame = this.autoConstHoname(this.handover.labgroupid, this.handover.classid);
      },
      getClassStartTime(classid){
          if(classid == ""){
              return XEUtils.toDateString(new Date(), "yyyy-MM-dd") + " 00:00:00";
          }
          var offclass = this.offclassOption.find((item)=>item.classid == classid);
          if(offclass){
              var class_starttime1 = offclass.starttime1.slice(0,2)+":" + offclass.starttime1.slice(offclass.starttime1.length-2,offclass.starttime1.length) ;
              var class_starttime2 = offclass.starttime2.slice(0,2)+":" + offclass.starttime2.slice(offclass.starttime2.length-2,offclass.starttime2.length) ;
              var class_endtime1 = offclass.endtime1.slice(0,2)+":" + offclass.endtime1.slice(offclass.endtime1.length-2,offclass.endtime1.length) ;
              var class_endtime2 = offclass.endtime2.slice(0,2)+":" + offclass.endtime2.slice(offclass.endtime2.length-2,offclass.endtime2.length) ;
              if(class_endtime1 == "23:59" && class_starttime2=="00:00" && class_endtime2 != "00:00"){
                  //跨天
                  return XEUtils.toDateString(new Date()-24 * 60 * 60 * 1000, "yyyy-MM-dd") + " " + class_starttime1+ ":00";
              }else{
                  return XEUtils.toDateString(new Date(), "yyyy-MM-dd") + " " + class_starttime1+ ":00";
              }
          }else{
              return XEUtils.toDateString(new Date(), "yyyy-MM-dd") + " 00:00:00";
          }
      },
      getClassEndTime(classid){
          if(classid == ""){
              return XEUtils.toDateString(new Date(), "yyyy-MM-dd") + " 23:59:59";
          }
          var offclass = this.offclassOption.find((item)=>item.classid == classid);
          if(offclass){
              var class_starttime2 = offclass.starttime2.slice(0,2)+":" + offclass.starttime2.slice(offclass.starttime2.length-2,offclass.starttime2.length) ;
              var class_endtime1 = offclass.endtime1.slice(0,2)+":" + offclass.endtime1.slice(offclass.endtime1.length-2,offclass.endtime1.length) ;
              var class_endtime2 = offclass.endtime2.slice(0,2)+":" + offclass.endtime2.slice(offclass.endtime2.length-2,offclass.endtime2.length) ;
              if(class_endtime1 == "23:59" && class_starttime2=="00:00" && class_endtime2 != "00:00"){
                  //跨天
                  return XEUtils.toDateString(new Date(), "yyyy-MM-dd") + " " + class_endtime2 + ":"+ (class_endtime2.slice(class_endtime2.length-2,class_endtime2.length) =="59" ? "59":"00");
              }else{
                  return XEUtils.toDateString(new Date(), "yyyy-MM-dd") + " " + class_endtime1 + ":"+ (class_endtime1.slice(class_endtime1.length-2,class_endtime1.length) =="59" ? "59":"00");
              }
          }else{
              return XEUtils.toDateString(new Date(), "yyyy-MM-dd") + " 23:59:59";
          }
      },
      QueryHandOver(){
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS360",
                  method: "post",
                  data: {
                      action: "queryhandover",
                      checkoutuser: this.searchObj.checkoutuser,
                      checkinuser: this.searchObj.checkinuser,
                      labgroupid: this.searchObj.labgroupid,
                      startdt:this.searchObj.startdt,
                      enddt:this.searchObj.enddt,
                  },
              }).then((res) => {
                  if(res.data.length > 0){
                      this.handoverTableData = res.data;
                      this.$refs.xTable.setCurrentRow(res.data[0]);
                      this.handover = JSON.parse(JSON.stringify(res.data[0]));
                      this.ChangeEditFlag();
                      this.QueryHandOverDet(this.handover.hoid);
                  }else{
                      this.handoverTableData = [];
                      this.handoverTableDetData = [];
                      this.handover = {};
                      this.iseditflag = false;
                  }
                  
              }).catch((e) => {

              });
      },
      ConfirmHand(){
          if(this.handover.checkinuser){
              this.$message.error("此单据已确认接单，无法再次确认！");
          }else{
              this.$tool
              .request({
                  url: "LIS/LIS3/LIS360",
                  method: "post",
                  data: {
                      action: "confirmhand",
                      hoid: this.handover.hoid,
                  },
              }).then((res) => {
                  this.selrow = this.$refs.xTable.getCurrentRow();
                  if(res.errcode != "1"){
                      this.$message.error("确认失败！" + res.errmsg);
                  }else {
                      this.$message.success("确认成功！");
                      this.changeflag = false;
                      this.iseditflag = false;
                      this.QueryHandOver();
                  }
                  this.$refs.xTable.setCurrentRow(this.selrow);
              }).catch((e) => {
              });
          }
           
      },
      ChangeEditFlag(){
          if ( this.handover.checkoutuser == this.loginemployee.userno) this.iseditflag = true;
          else  this.iseditflag = false;
      },
      
      AddHandOver(){
          this.HasChange();
          this.iseditflag = true;
          var newhandover = {
              hoid: undefined,
              hotime: XEUtils.toDateString(new Date(), "yyyy-MM-dd HH:mm:ss"),
              honame: this.offclassOption && this.offclassOption.length >0 && this.loginemployee.labgroupid ? this.autoConstHoname(this.loginemployee.labgroupid, this.offclassOption[0].classid) : "",
              checkoutuser: this.loginemployee.userno,
              checkinuser: "",
              checkintime: undefined,
              comments: "",
              labgroupid: this.loginemployee.labgroupid ? this.loginemployee.labgroupid : "",
              classid: this.offclassOption && this.offclassOption.length >0 ? this.offclassOption[0].classid : "",
              class_starttime: this.getClassStartTime(this.offclassOption && this.offclassOption.length >0 ? this.offclassOption[0].classid : ""),
              class_endtime: this.getClassEndTime(this.offclassOption && this.offclassOption.length >0 ? this.offclassOption[0].classid : ""),
          };
          this.handoverDetTableData = [];
          this.handover = newhandover;
      },

      SaveHandOver(){
          let det_datatable = this.$refs.xTable1.getRecordset();
          if(!this.handover.checkoutuser){
              this.$message.error("请输入交班人！");
              return;
          }
          this.loading = true;
          this.loading1 = true;
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS360",
                  method: "post",
                  data: {
                      action: "savehandover",
                      operatetype: 1,
                      handover: this.handover,
                      handoverdet: det_datatable,
                  },
              }).then((res) => {
                  if(res.errcode != "1"){
                      this.$message.error("保存失败！" + res.errmsg);
                  }else {
                      this.$message.success("保存成功！");
                      this.changeflag = false;
                      if(this.handover.hoid){
                          this.selrow.hotime = this.handover.hotime;
                          this.selrow.honame = this.handover.honame;
                          this.selrow.checkoutuser = this.handover.checkoutuser;
                          this.selrow.checkinuser = this.handover.checkinuser;
                          this.selrow.checkintime = this.handover.checkintime;
                          this.selrow.labgroupid = this.handover.labgroupid;
                          this.selrow.comments = this.handover.comments;
                          this.selrow.class_endtime = this.handover.class_endtime;
                          this.selrow.classid = this.handover.checkintimeclassid;
                          this.selrow.class_starttime = this.handover.class_starttime;
                      }else if(res.hoid){
                          this.handover.hoid = res.hoid;
                          this.selrow = {"class_endtime":this.handover.class_endtime,"checkinuser":this.handover.checkinuser,"labgroupid":this.handover.labgroupid,"comments":this.handover.comments,"honame":this.handover.honame,"hoid":this.handover.hoid,"class_starttime":this.handover.class_starttime,"checkoutuser":this.handover.checkoutuser,"checkintime":this.handover.checkintime,"classid":this.handover.classid,"hotime":this.handover.hotime,"hoid":res.hoid};
                          this.$refs.xTable.insertAt(this.selrow,-1).then(({ row }) => {
                              this.$refs.xTable.setCurrentRow(row);
                              this.$refs.xTable.scrollToRow(row);
                          });;
                      }
                  }
                  this.loading = false;
                  this.loading1 = false;
              }).catch((e) => {
                  this.loading = false;
                  this.loading1 = false;
              });
      },

      DeleteHandOver(){
          this.$confirm("你确定删除这笔记录?", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
          }).then(() => {
              this.$tool
              .request({
                  url: "LIS/LIS3/LIS360",
                  method: "post",
                  data: {
                      action: "savehandover",
                      operatetype: 3,
                      handover:this.handover,
                  },
              }).then((res) => {
                  if(res.errcode != "1"){
                      this.$message.error("删除失败！" + response.errmsg);
                  }else {
                      this.$message.success("删除成功！");
                      this.QueryHandOver();
                  }
              }).catch((e) => {
              });
          });
      },

      btnAddHandOverDet(){
          this.HasChange();
          this.$refs.xTable1.insertAt({},-1).then(({ row }) => {
              this.$refs.xTable1.setActiveCell(row, "rptunitid");
              this.$refs.xTable1.setCurrentRow(row);
              this.$refs.xTable1.scrollToRow(row);
          });
      },

      btnDeleteHandOverDet() {
          try {
              this.HasChange();
              var delrow = this.$refs.xTable1.getCurrentRow();
              if (delrow) {
                  var alld = this.$refs.xTable1.tableData;
                  var rowindex = alld.indexOf(delrow);
                  this.$refs.xTable1.remove(delrow);
                  let havedata = this.$refs.xTable1.tableData;
                  if (havedata.length > 0) {
                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                      let selectrow = havedata[rowindex];
                      this.$refs.xTable1.setCurrentRow(selectrow);
                  } else {
                      this.$refs.xTable1.setCurrentRow(null);
                  }
              }
          } catch (e) {
              console.log("error", e);
          }
      },

      getUnitShowName(code) {
          var rptunit = this.rptunitOption.find((item) => item.data == code);
          if (rptunit) return rptunit.display
          else return undefined;
      },
      //格式化
      formatFun({ cellValue, column }) {
          return this.commFormatFun(cellValue, column.property);
      },
      //格式化数据
      commFormatFun(cellValue, column) {
          if (column == "labgroupid") {
              try {
                  let option_item = this.labgroupOption.find((m) => m.data == cellValue);
                  if (option_item != undefined && option_item != null) {
                      return option_item.display;
                  } else {
                      return cellValue;
                  }
              } catch {}
          }else if (column == "checkoutuser" || column == "checkinuser") {
              try {
                  let option_item = this.userOption.find((m) => m.data == cellValue);
                  if (option_item != undefined && option_item != null) {
                      return option_item.display;
                  } else {
                      return cellValue;
                  }
              } catch {}
          }else if (column == "offclass") {
              try {
                  let option_item = this.offclassOption.find((m) => m.classid == cellValue);
                  if (option_item != undefined && option_item != null) {

                      return option_item.classname;
                  } else {
                      return cellValue;
                  }
              } catch {}
          }else {
              return cellValue;
          }
      },

      //计算明细数据
      btnStatisticsData(){
          if(this.handoverDetTableData && this.handoverDetTableData.length > 0){
              this.$confirm("此操作将清空界面上的所有报告单元明细，是否继续?", "提示", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
              }).then(() => {
                  this.StatisticsData();
              });
          }else{
              this.StatisticsData();
          }
      },
      StatisticsData(){
          this.HasChange();
          this.loading1 = true;
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS360",
                  method: "post",
                  data: {
                      action: "statisticsdata",
                      operatetype: 3,
                      labgroupid: this.handover.labgroupid,
                      starttime: this.handover.class_starttime,
                      endtime: this.handover.class_endtime,
                      set_shownodata: (this.set_shownodata) ? "0":"1",
                      set_unchecktime: this.set_unchecktime,
                  },
              }).then((res) => {
                  if(!res || res.errcode == "0"){
                      this.$message.error("计算出现异常！" + res.errmsg);
                      this.loading1 = false;
                  }
                  this.$refs.xTable1.setAllSelection(true);
                  this.$refs.xTable1.removeSelecteds();//删除所有行
                  if(res.data && res.data.length > 0){
                      res.data.forEach((item) => {
                          this.$refs.xTable1.insertAt(item);
                      })
                  }
                  this.$message.success("计算成功！");
                  this.loading1 = false;
              }).catch((e) => {
              });
      },
      currentChangeEvent({ row, column }) {
          this.selrow = row;
          this.handover = JSON.parse(JSON.stringify(this.selrow));
          this.changeflag = false;
          this.ChangeEditFlag();
          this.QueryHandOverDet(row.hoid);
      },

      QueryHandOverDet(hoid){
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS360",
                  method: "post",
                  data: {
                      action: "queryhandoverdet",
                      hoid: hoid,
                  },
              }).then((res) => {
                  this.handoverDetTableData = res.data;
              }).catch((e) => {

              });
      },

      xTableRowClassName({ row, rowIndex }) {
          let isDirty = this.$refs.xTable.hasRowChange(row);
          if (isDirty) {
              return "row-modify";
          }
          if (this.$refs.xTable.hasRowInsert(row)) {
              return "row-new";
          }
      },

      ExportMasterExcel() {
          let tableColumn = this.$refs.xTable.getColumns();
          let extableColumn = [];
          tableColumn.forEach((item) => {
              extableColumn.push({ title: item.title, field: item.property });
          });
          var exData = XEUtils.clone(this.handoverTableData,true);
          exData.forEach((item) => {
              item.checkinuser = this.commFormatFun(item.checkinuser,"checkinuser");
              item.checkoutuser = this.commFormatFun(item.checkoutuser,"checkoutuser");
              item.labgroupid = this.commFormatFun(item.labgroupid,"labgroupid");
          })
          this.$pub.exportTableExcel(exData, extableColumn, "LIS360 检验交班记录单.xlsx");
      },

      ExportDeatilExcel() {
          let tableColumn = this.$refs.xTable1.getColumns();
          let extableColumn = [];
          tableColumn.forEach((item) => {
              extableColumn.push({ title: item.title, field: item.property });
          });
          var exData = XEUtils.clone(this.handoverDetTableData,true);
          exData.forEach((item) => {
              item.rptunitid = this.getUnitShowName(item.rptunitid);
          })
          this.$pub.exportTableExcel(exData, extableColumn, "LIS360 检验交班记录单明细.xlsx");
      },

      HasChange(){
          if(!this.changeflag) this.changeflag = true;
      },

      CancelChange() {
          this.$confirm("此操作将取消所有改动，是否继续?", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
          }).then(() => {
              this.iseditflag = false;
              this.changeflag = false;
              this.QueryHandOver();
          });
      },
      printrecord() {
          this.styleid = "5105";
          var master_data = this.handover;
          var detail_data = JSON.parse(JSON.stringify(this.$refs.xTable1.tableData));
          var p_data = [];
          detail_data.forEach((item)=>{
              p_data.push(Object.assign(item,this.handover));
          });
          if (!this.handover.hoid) {
              this.$message.error("错误：没有要打印的数据！");
          } else {
               var column = XEUtils.clone(this.$refs.xTable1.getTableColumn().tableColumn,true);
                  this.$refs.xTable.getTableColumn().tableColumn.forEach((item)=>{
                      column.push(item);
                 });
              let str = JSON.stringify(this.$pub.InitColumn(column));
              str += "\r";
              p_data.forEach((item)=>{
                  item.rptunitid = this.getUnitShowName(item.rptunitid);
                  item.checkinuser = this.commFormatFun(item.checkinuser,"checkinuser");
                  item.checkoutuser = this.commFormatFun(item.checkoutuser,"checkoutuser");
                  item.labgroupid = this.commFormatFun(item.labgroupid,"labgroupid");
              });
              str += JSON.stringify(p_data);
              let sql = btoa(encodeURIComponent(str));
              jsObj.PrintCustomJsonReport(this.styleid, sql, "admin", "检验交班表", "");
          }
      },
      RptStyleSetting(type) {
          this.styleid = "5105";
          var user = this.$tool.getSession(this.$tool.loginuserno);
          if (user != "admin") {
              this.$message.error("如需调整样式请联系管理员。");
          } else {
              var detail_data = JSON.parse(JSON.stringify(this.$refs.xTable1.tableData));
              var p_data = [];
              detail_data.forEach((item)=>{
                 p_data.push(Object.assign(item,this.handover));
              });
              if (this.handover.hoid) {
                  const rload = this.$pub.openLoading(this, "正在打开报表设计器，请稍候……");

                  var column = XEUtils.clone(this.$refs.xTable1.getTableColumn().tableColumn,true);
                  this.$refs.xTable.getTableColumn().tableColumn.forEach((item)=>{
                      column.push(item);
                 });
                  let str = JSON.stringify(this.$pub.InitColumn(column));
                  str += "\r";
                  str += JSON.stringify(p_data);
                  let sql = btoa(encodeURIComponent(str));
                  jsObj.SetCustomJsonPrintConfig(this.styleid, sql, "admin", "检验交班表");
                  rload.close();
              } else {
                  this.$message.error("错误：没有要打印的数据！");
              }
          }
      },
      DbTextArea(){
          if(this.iseditflag && this.handover.checkinuser == ''){
              this.dialogTablePopVisible=true;
          }
      },
      popcomchange(c, v, row) {
          this.HasChange();
          this.handover.comments = v;
          this.dialogTablePopVisible = false;
      },
      shownodataChange(){
          localStorage.setItem("lis360set_shownodata", this.set_shownodata == false ? "0":"1");
      },
      unchecktimeChange(){
          localStorage.setItem("lis360set_unchecktime", this.set_unchecktime);
      },
      autoConstHoname(labgroupid,classid){
          if(labgroupid && classid){
              var grpname = this.commFormatFun(labgroupid,"labgroupid");
              var classname = this.commFormatFun(classid,"offclass");
              if(grpname && classname) return grpname+classname;
              else return "";
          }else{
              return "";
          }
      },
      labgroup_Change(){
          this.HasChange();
          this.handover.honame = this.autoConstHoname(this.handover.labgroupid,this.handover.classid);
      },
  },
};
</Script>

<style scoped>
/deep/ tr.vxe-body--row.row-new {
  color: #cc6600;
}
/deep/ tr.vxe-body--row.row-modify {
  color: blue !important;
}
.pagetop {
  width: 100%;
  height: 65px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  padding: 5px 0;
  z-index: 99;
}
.right-bottom-top{
  width: 100%;
  height: 35px;
  position: absolute;
  padding: 5px 0;
  z-index: 99;
}
.right-bottom-bottom{
  width: 100%;
  top: 40px;
  position: absolute;
  height: calc(100% - 40px);
}
.pagecenter {
  position: absolute;
  top: 70px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.table1style tr td {
  padding: 0px 2px 0px 2px;
}

/deep/.el-button.is-disabled {
  border: 0px;
  color: grey;
  background-color: #e6e6e6;
  font-weight: normal;
}

/deep/.right-bottom .vxe-table .vxe-cell {
  line-height: 18px !important;
}

/deep/.el-input.is-disabled .el-input__inner {
  color: #000000;
  color: #000000;
  border: 0px;
  cursor: default;
}

/deep/.el-textarea.is-disabled .el-textarea__inner{
      color: #000000;
  color: #000000;
  border: 0px;
  cursor: default;
}

</style>